# coding=utf-8
from sutras import enums, models


def get_temple_list():
    temple_objs = models.Temple.objects.filter(
        status=enums.TempleStatus.normal)
    temple_list = []
    for temple_obj in temple_objs:
        temple_list.append({
            "id": temple_obj.id,
            "name": temple_obj.name,
            "img_url": temple_obj.img_url,
        })
    return temple_list


def delete_temple(temple_id):
    models.Temple.objects.filter(pk=temple_id).update(
        status=enums.TempleStatus.delete)


def create_temple(name, img_url):
    models.Temple.objects.create(name=name, img_url=img_url)


def get_temple(temple_id):
    temple_obj = models.Temple.objects.filter(
        status=enums.TempleStatus.normal).first()
    return {
        "name": temple_obj.name,
        "img_url": temple_obj.img_url,
    }


def update_temple(temple_id, name, img_url):
    models.Temple.objects.filter(
        pk=temple_id).update(name=name, img_url=img_url)
